import { get, post, put, del } from '@/utils/request';
import {ApiMenuItem, MenuRouterResponse} from '@/store/menuStore.tsx';
export interface MenuListParams {
    pageSize: number;
    pageNum: number;
}
export interface MenuResponse {
    children: any[];
    component: string;
    createBy: string;
    createTime: string;
    icon: string;
    isCache: string;
    isFrame: string;
    menuId: number;
    menuName: string;
    menuType: string;
    name: string;
    orderNum: number;
    parentId: number;
    parentName: string;
    path: string;
    perms: string;
    query: string;
    remark: string;
    status: string;
    updateBy: string;
    updateTime: string;
    visible: string;
}

export const getRoutersApi = () => {
    return get<MenuRouterResponse>('/getRouters');
};
/**
 * 查询菜单列表
 * @returns {MenuResponse[]} 节点路径数组，未找到返回 null
 * @param params {MenuListParams}
 */
export const getMenuListApi = (params: MenuListParams) => {
    return get<MenuResponse[]>('/system/menu/list', params);
};

/**
 * 新增菜单
 * @param params {MenuResponse}
 */
export const insertMenuApi = (params: MenuResponse) => {
    return post('/system/menu', params);
};

/**
 * 更新菜单
 * @param params {MenuResponse}
 */
export const updateMenuApi = (params: MenuResponse) => {
    return put('/system/menu', params);
};

/**
 * 删除菜单
 * @param id
 */
export const deleteMenuApi = (id: number) => {
    return del(`/system/menu/${id}`);
};

export const getMenuTreeSelectApi = () => {
    return get(`/system/menu/treeselect`);
}
